﻿using System;

public class Vector2
{
    public float x;
    public float y;
    public Vector2(float x, float y)
    {
        this.x = x;
        this.y = y;
    }
    public Vector2(Vector2 p1, Vector2 p2)
    {
        this.x = p2.x-p1.x;
        this.y = p2.y-p1.y;
    }
    public Vector2(Vector2 v)
    {
        this.x = v.x;
        this.y = v.y;
    }
    public float length()
    {
        return (float)(Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)));
    }
    public float lengthSquared()
    {
        return (float)(Math.Pow(x, 2) + Math.Pow(y, 2));
    }
    public void normalize()
    {
        float n = this.length();
        if (n != 0)
        {
            this.x /= n;
            this.y /= n;
        }
    }
    public override string ToString()
    {
        return "(" + x + ", " + y + ")";
    }
    public static Vector2 operator +(Vector2 v)
    {
        return new Vector2(v.x, v.y);
    }
    public static Vector2 operator -(Vector2 v)
    {
        return new Vector2(-v.x, -v.y);
    }
    public static Vector2 operator *(float k, Vector2 v)
    {
        return new Vector2(k * v.x, k * v.y);
    }
    public static Vector2 operator *(Vector2 v, float k)
    {
        return new Vector2(k * v.x, k * v.y);
    }
    public static Vector2 operator /(Vector2 v, float k)
    {
        if (k != 0)
            return new Vector2(v.x / k, v.y / k);
        else
            throw new Exception("Division by 0!");
    }
    public static Vector2 operator +(Vector2 v1, Vector2 v2)
    {
        return new Vector2(v1.x+v2.x, v1.y+v2.y);
    }
    public static Vector2 operator -(Vector2 v1, Vector2 v2)
    {
        return new Vector2(v1.x - v2.x, v1.y - v2.y);
    }
    public static Vector2 operator /(Vector2 v1, Vector2 v2)
    {
        if(v2.x!=0 && v2.y!=0)
            return new Vector2(v1.x / v2.x, v1.y / v2.y);
        else
            throw new Exception("Division by 0!");
    }
    public static Vector2 operator *(Vector2 v1, Vector2 v2)
    {
        return new Vector2(v1.x * v2.x, v1.y * v2.y);
    }
    public float dot(Vector2 v)
    {
        return (this.x * v.x + this.y * v.y);
    }
}